import { useState } from 'react';
import styles from './NetDemon.module.scss';
import {mock} from 'mockjs'
import { getUser, postUser,deleteUser } from '@/apis/demon';
interface TProps {}
enum TNetType {
  Get,
  Post,
  Delete,
  Put,
}

const NetDemon = ({}: TProps) => {
  const [netData, setNetData] = useState<any>();

  const netHandle = async (type: TNetType = TNetType.Get) => {
    switch (type) {
      case TNetType.Get:
        const data = await getUser();
        setNetData(data)
        break;
      case TNetType.Post:
        const postRes = await postUser({nikeName:mock('@cname'),account:mock('@name'),password:mock('@guid')});
        setNetData(postRes)
        break;
      case TNetType.Delete:
        const delRes = await deleteUser();
        setNetData(delRes)
        break;
      default:
        break;
    }
  };
  return (
    <div className={styles['NetDemonBox']}>
      <h3>网络请求测试</h3>
      <button
        onClick={() => {
          netHandle();
        }}
      >
        获取User
      </button>
      <button
        onClick={() => {
          netHandle(TNetType.Post);
        }}
      >
        添加User
      </button>
      <button
        onClick={() => {
          netHandle(TNetType.Delete);
        }}
      >
        删除User
      </button>
      <p>{
        JSON.stringify(netData)
        }</p>
    </div>
  );
};

export default NetDemon;
